package com.lu.service.student;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lu.entity.Student;
import com.lu.mapper.StudentMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class StudentService implements StudentServices{
    @Autowired
    private StudentMapper studentMapper;

    //查询学生所有数据
    @Override
    public List<Student> getStudents(Integer currentPage, Integer pageSize) {
        PageHelper.startPage(currentPage,pageSize);
        List<Student> students = studentMapper.findAll();
        return new PageInfo<>(students).getList();
    }

    //通过传入id删除学生数据
    @Override
    public void deleteStudent(Integer id) {
        studentMapper.deleteById(id);
    }

    //通过id获取学生数据
    @Override
    public List<Student> getStudentsById(Integer id) {
        return studentMapper.findById(id);
    }

    //修改学生数据
    @Override
    public void updateStudent(Student student) {
        studentMapper.updateData(student);
    }

    //添加学生数据
    @Override
    public void insertStudent(Student student) {
        studentMapper.insertData(student);
    }

    //根据传入的学号和姓名查询对应的数据
    @Override
    public List<Student> getStudentsByStdName(Student student) {
        return studentMapper.findByStdName(student);
    }
}
